package com.openness.crawler.hbase;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.hadoop.hbase.util.Bytes;

/**
 * @author Rain
 * @version 2013-5-22 下午3:50:08
 */

public class Row {

	private byte[] row;

	private Map<String, byte[]> qualifiers;

	public Row(byte[] row) {
		this.row = row;

		this.qualifiers = new HashMap<String, byte[]>();
	}

	public Row(byte[] row, Map<String, byte[]> qualifiers) {
		this.row = row;

		this.qualifiers = qualifiers;
		if (this.qualifiers == null) {
			this.qualifiers = new HashMap<String, byte[]>();
		}
	}

	public byte[] getRow() {
		return row;
	}

	public void setRow(byte[] row) {
		this.row = row;
	}

	public Map<String, byte[]> getQualifiers() {
		return qualifiers;
	}

	public Map<byte[], byte[]> getQualifiersByByteArray() {
		Map<byte[], byte[]> result = new HashMap<byte[], byte[]>();

		for (Entry<String, byte[]> entry : this.qualifiers.entrySet()) {
			result.put(Bytes.toBytes(entry.getKey()), entry.getValue());
		}

		return result;
	}

	public void setQualifiers(Map<String, byte[]> qualifiers) {
		this.qualifiers = qualifiers;
	}

	public byte[] getQualifierValue(String qualifier) {
		return this.qualifiers.get(qualifier);
	}

	public void add(String qualifier, byte[] value) {
		this.qualifiers.put(qualifier, value);
	}

	public void remove(String qualifier) {
		this.qualifiers.remove(qualifier);
	}

	public int length() {
		return this.qualifiers.size();
	}

}
